﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MCWEBSITE.BUL;
using System.IO;

public partial class Modules_WebsiteFrontSub_wucProductDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int ItemId = Convert.ToInt32(Request.QueryString["ItemId"]);
            this.BindData(ItemId);
        }
    }

    protected void BindData(int ItemId)
    {
        try
        {
            DataSet objDs = websiteProductBUL.GetDetails(ItemId);
            imgThumb.ImageUrl = ConvertURL((string)objDs.Tables[0].Rows[0]["Image"].ToString());
            lblName.Text = (string)objDs.Tables[0].Rows[0]["ItemName"].ToString();
            lblCode.Text = "Mã sản phẩm: " + (string)objDs.Tables[0].Rows[0]["ItemCode"].ToString();
            lblPrice.Text = "Giá:" + (string)objDs.Tables[0].Rows[0]["Sale"].ToString();
            lblDescription.Text = (string)objDs.Tables[0].Rows[0]["Description"].ToString();
        }
        catch
        {

        }
    }

    public string ConvertURL(string strImage)
    {
        try
        {
            string fileName = "";
            DirectoryInfo URL = new DirectoryInfo(Server.MapPath(strImage));
            foreach (FileInfo file in URL.GetFiles())
            {
                if (file.Name != "vssver2.scc" && file.Name != "Thumbs.db")
                {
                    fileName = file.Name.ToString();
                    break;
                }
            }
            return strImage + "/" + fileName.ToString();
        }
        catch
        {
            return "";
        }
    }
}
